<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">

    <div class="dialog-title">
      <span>项目信息</span>
    </div>
    <div class="btn-cantainer">
      <el-button type="primary" @click="submitForm">送检</el-button>

      <el-button type="primary" @click="submitForm">保存</el-button>
      <el-button  @click="dialogVisible = false">返回</el-button>
    </div>
  <ContentWrap>
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
      :inline="true"
    >
      <el-form-item label="项目名称" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目名称" />
      </el-form-item>
      <el-form-item label="项目起始日期" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目起始日期" />
      </el-form-item>
      <el-form-item label="项目截止日期" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目截止日期" />
      </el-form-item>
      <el-form-item label="甲方单位" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入甲方单位" />
      </el-form-item>
      <el-form-item label="合同金额" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同金额（万元)" />
      </el-form-item>
      <el-form-item label="合同编号" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同编号" />
      </el-form-item>
      <el-form-item label="项目管理员" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
   
    </el-form>
  </ContentWrap>

  <div class="dialog-title">
      <span>样品信息</span>
    </div>
  <ContentWrap>
   
    基本信息
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
      :inline="true"
    >
      <el-form-item label="样品名称" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目名称" />
      </el-form-item>
      <el-form-item label="样品编号" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目起始日期" />
      </el-form-item>
      <el-form-item label="盲样编号" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目截止日期" />
      </el-form-item>
      <el-form-item label="规格型号" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入甲方单位" />
      </el-form-item>
      <el-form-item label="执行标准" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同编号" />
      </el-form-item>
      <el-form-item label="委托单位" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同金额（万元)" />
      </el-form-item>

      <el-form-item label="受检单位" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="生产单位" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
   
    </el-form>
    </ContentWrap>


    <ContentWrap>
    抽样信息

    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
      :inline="true"
    >
      <el-form-item label="抽样地点" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目名称" />
      </el-form-item>
      <el-form-item label="抽样日期" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目起始日期" />
      </el-form-item>
      <el-form-item label="样品批（罐）号" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目截止日期" />
      </el-form-item>
      <el-form-item label="生产日期" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入甲方单位" />
      </el-form-item>
      <el-form-item label="产品包装" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同编号" />
      </el-form-item>
      <el-form-item label="存放条件" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入合同金额（万元)" />
      </el-form-item>

      <el-form-item label="物资编码" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="抽样基数" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>

      <el-form-item label="抽取样品量" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="封样形式" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="运送方式" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="抽样人员" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="陪同抽样人" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="受检单位人员" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="抽样方式" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
   
    </el-form>
  </ContentWrap>
<ContentWrap>
    退样说明
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
      :inline="true"
    >


        <el-form-item label="抽样方式" prop="projectId">
          <el-radio-group v-model="formData.resource">
        <el-radio value="Sponsor">不退</el-radio>
        <el-radio value="Venue">退</el-radio>
        <el-radio value="Venue">部分退</el-radio>
      </el-radio-group>
        </el-form-item>

        <el-form-item label="退样收货人" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="退样收货地址" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>
      <el-form-item label="退样收货联系方式" prop="projectId">
        <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
      </el-form-item>



    </el-form>
  </ContentWrap>
<ContentWrap>
    检验要求
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
      :inline="true"
    >

    <el-form-item label="抽样状态" prop="standardType">
        <el-select
          v-model="formData.standardType"
          placeholder="请选择标准类型：0-手填 1-选择"
          clearable
          class="!w-240px"
        >
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>

    <el-form-item label="检验时限">
      <el-select v-model="formData.region" placeholder="please select your zone" class="!w-240px">
        <el-option label="Zone one" value="shanghai"  />
      </el-select>
    </el-form-item>

    <el-form-item label="承检机构">
      <el-select v-model="formData.region" placeholder="please select your zone" class="!w-240px">
        <el-option label="Zone one" value="shanghai" />
      </el-select>
    </el-form-item>

    <el-form-item label="结果要求" prop="projectId">
          <el-radio-group v-model="formData.resource">
        <el-radio value="Sponsor">出具检测结果</el-radio>
        <el-radio value="Venue">判定检验结果</el-radio>
      </el-radio-group>
        </el-form-item>

        <el-form-item label="指标要求" prop="projectId">
          <el-radio-group v-model="formData.resource">
        <el-radio value="Sponsor">指定检测项目</el-radio>
        <el-radio value="Venue">按照检验依据要求</el-radio>
      </el-radio-group>
        </el-form-item>
        <div>
          <el-form-item label="检验依据" prop="projectId">
            <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
        </el-form-item>
        </div>
        <div>
          <el-form-item label="备注" prop="projectId">
            <el-input v-model="formData.projectId" placeholder="请输入项目管理员" />
        </el-form-item>
        </div>
        <div>
          <el-form-item label="附件上传" prop="projectId">
            <el-upload
    v-model:file-list="fileList"
    class="upload-demo"
    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
    multiple
    :on-preview="handlePreview"
    :on-remove="handleRemove"
    :before-remove="beforeRemove"
    :limit="3"
    :on-exceed="handleExceed"
  >
  <el-button >
      <el-icon><UploadFilled /></el-icon>
      添加</el-button>

  </el-upload>
        </el-form-item>
        </div>
  </el-form>
  </ContentWrap>
<ContentWrap>
  抽样单签字版扫描件、样品照片
  <el-upload
    v-model:file-list="fileList"
    class="upload-demo"
    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
    multiple
    :on-preview="handlePreview"
    :on-remove="handleRemove"
    :before-remove="beforeRemove"
    :limit="3"
    :on-exceed="handleExceed"
  >
    <el-button >
      <el-icon><UploadFilled /></el-icon>
      添加</el-button>

  </el-upload>
</ContentWrap>
  </Dialog>
</template>
<script setup lang="ts">
import { SampleInformationApi, SampleInformationVO } from '@/api/qis/sampleinformation'
import { UploadFilled } from '@element-plus/icons-vue'
/** 质检平台-样本信息 表单 */
defineOptions({ name: 'SampleInformationForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData = ref({
  id: undefined,
  projectId: undefined,
  status: undefined,
  sampleName: undefined,
  sampleNum: undefined,
  blindSampleNum: undefined,
  model: undefined,
  executiveStandard: undefined,
  standardType: undefined,
  entrustCompany: undefined,
  receiveCheckCompany: undefined,
  productionCompany: undefined,
  samplingSite: undefined,
  samplingDate: undefined,
  sampleBatchNum: undefined,
  productionDate: undefined,
  productPackaging: undefined,
  storeCondition: undefined,
  sampleCode: undefined,
  samplingCardinalNum: undefined,
  samplingQuantity: undefined,
  sealedSampleMethod: undefined,
  deliveryType: undefined,
  samplingPerson: undefined,
  accompanySamplingPerson: undefined,
  receiveCheckCompanyPerson: undefined,
  samplingType: undefined,
  returnSanpleType: undefined,
  returnSanpleReceiveBy: undefined,
  returnSanpleReceiveAddress: undefined,
  returnSanpleReceivePhone: undefined,
  checkType: undefined,
  checkTimeLimit: undefined,
  orgId: undefined,
  resultRequire: undefined,
  targetRequire: undefined,
  checkAccordingTo: undefined,
  requireRemark: undefined,
  requireAttachment: undefined,
  reportNum: undefined,
  checkStartTimr: undefined,
  checkEndTimr: undefined,
  reportDate: undefined,
  labName: undefined,
  mainCheckDevice: undefined,
  checkState: undefined,
  checkConclusion: undefined,
  checkPerson: undefined,
  returnReason: undefined,
  signAndSampleUrl: undefined,
  checkReportUrl: undefined,
})
const formRules = reactive({
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type: string, id?: number) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.' + type)
  formType.value = type
  resetForm()
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await SampleInformationApi.getSampleInformation(id)
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  await formRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    const data = formData.value as unknown as SampleInformationVO
    if (formType.value === 'create') {
      await SampleInformationApi.createSampleInformation(data)
      message.success(t('common.createSuccess'))
    } else {
      await SampleInformationApi.updateSampleInformation(data)
      message.success(t('common.updateSuccess'))
    }
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
  }
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    projectId: undefined,
    status: undefined,
    sampleName: undefined,
    sampleNum: undefined,
    blindSampleNum: undefined,
    model: undefined,
    executiveStandard: undefined,
    standardType: undefined,
    entrustCompany: undefined,
    receiveCheckCompany: undefined,
    productionCompany: undefined,
    samplingSite: undefined,
    samplingDate: undefined,
    sampleBatchNum: undefined,
    productionDate: undefined,
    productPackaging: undefined,
    storeCondition: undefined,
    sampleCode: undefined,
    samplingCardinalNum: undefined,
    samplingQuantity: undefined,
    sealedSampleMethod: undefined,
    deliveryType: undefined,
    samplingPerson: undefined,
    accompanySamplingPerson: undefined,
    receiveCheckCompanyPerson: undefined,
    samplingType: undefined,
    returnSanpleType: undefined,
    returnSanpleReceiveBy: undefined,
    returnSanpleReceiveAddress: undefined,
    returnSanpleReceivePhone: undefined,
    checkType: undefined,
    checkTimeLimit: undefined,
    orgId: undefined,
    resultRequire: undefined,
    targetRequire: undefined,
    checkAccordingTo: undefined,
    requireRemark: undefined,
    requireAttachment: undefined,
    reportNum: undefined,
    checkStartTimr: undefined,
    checkEndTimr: undefined,
    reportDate: undefined,
    labName: undefined,
    mainCheckDevice: undefined,
    checkState: undefined,
    checkConclusion: undefined,
    checkPerson: undefined,
    returnReason: undefined,
    signAndSampleUrl: undefined,
    checkReportUrl: undefined,
  }
  formRef.value?.resetFields()
}
</script>

<style lang="scss" scoped>
.dialog-title {
  font-weight: bold;

}

.btn-cantainer{
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
    align-items: center;
  }
</style>


